const getters = {
  sidebar: state => state.app.sidebar,
  size: state => state.app.size,
  device: state => state.app.device,
  visitedViews: state => state.tagsView.visitedViews,
  cachedViews: state => state.tagsView.cachedViews,
  token: state => state.user.token,
  user: state => state.user.user,
  refresh_token: state => state.user.refresh_token,
  expires_in: state => state.user.expires_in,
  // permissions: state => state.user.permissions,
  // permission_routes: state => state.permission.routes,
  menuList: state => state.menu.menuList,
  menuTree: state => state.menu.menuTree,
  leftMenuTitle: state => state.app.leftTitle,
  moudelId: state => state.app.moudelId,
  menuCode: state => state.app.menuCode,
  homeUrl: state => state.app.homeUrl,
  systemCountNum: state => state.app.systemCountNum,
  taskForm: state => state.taskForm,
  userCache: state => state.user.userCache,
  staffBusinessOpportunitySources: state => state.user.userCache.staffBusinessOpportunitySources || [],
  transferPhone: state => state.user.userCache.transferPhone,
  staffSkills: state => (state.user.userCache.businessGroupList || []).map(e => ({ id: e.groupNo, name: e.groupName })),
  skillInfoList: state => (state.user.userCache.skillInfoList || []).map(e => ({ id: e.skillNo, name: e.skillName })),
  // 组织
  groupList: state => {
    return state.user.userCache.businessGroupList || []
  },
  // 话务平台
  callPlatform: state => {
    return state.user.userCache.callPlatform
  },
  // 部门
  deptList: state => {
    return state.user.userCache.departmentInfoList || []
  },
  // 取第一个部门
  firstDept: state => {
    const t = state.user.userCache.departmentInfoList || []
    return t.length > 0 ? t[0].deptNo : ''
  },
  // 取第一个业务组
  firstGroup: state => {
    const t = state.user.userCache.businessGroupList || []
    return t.length > 0 ? t[0].groupNo : ''
  },
  // 取第一个业务组名
  firstGroupName: state => {
    const t = state.user.userCache.businessGroupList || []
    return t.length > 0 ? t[0].groupName : ''
  },
  // 员工码
  staffCode: state => {
    return state.user.userCache.staffCode
  },
  // 员工姓名
  staffName: state => {
    return state.user.userCache.staffName
  },
  // 员工账号
  accountNo: state => {
    return state.user.userCache.accountNo
  },
  // 办事处
  remoteOffice: state => {
    const user = state.user
    const uc = user.userCache
    const offices = []
    // agencies
    if (user.agencies instanceof Array && user.agencies.length > 0) {
      offices.push(...user.agencies.map(e => {
        return {
          'orgId': e.orgId,
          'parentId': e.parentId || '',
          'orgCode': e.orgCode,
          'otherCode': e.agencyCode,
          'orgName': e.agencyName,
          'orgType': 3
        }
      }))
    }
    // org
    if (user.org instanceof Array && user.org.length > 0) {
      offices.push(...user.org.filter(e => e.parentType === 3 || e.parentType === '3').map(e => {
        return {
          'orgId': e.parentId,
          'parentId': '',
          'orgCode': e.parentCode,
          'otherCode': e.parentOtherCode,
          'orgName': e.parentName,
          'orgType': e.parentType
        }
      }))
    }
    // remoteOrganizations
    if (uc.remoteOrganizations instanceof Array && uc.remoteOrganizations.length > 0) {
      offices.push(...uc.remoteOrganizations.filter(e => e.orgType === 3 || e.orgType === '3'))
    }
    const t = {}
    for (const item of offices) {
      if (!t[item.orgCode + item.otherCode]) {
        t[item.orgCode + item.otherCode] = item
      }
    }
    return Object.values(t)
  },
  // 办事处id
  otherCode: (state, getters) => {
    return getters.remoteOffice.map(e => e.otherCode).filter(e => e !== '' && e !== undefined)
  }
}
export default getters
